home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Source Code
/
Pascal
/
Code Resources
/
Ingis WDEF 1.3
/
Demo ƒ
/
Globals ƒ
/
CustomStubs.p
next >
Wrap
Text File
|
1997-05-09
|
8KB
|
196 lines
{ *** DEMO FOR the IngisWDEF WDEF building package *** }
{© 1997 by Ingemar Ragnemalm}
{You may use it freely as long as credits are given in the final program.}
{This is a variation on the "Simple" demo that uses two "cicn" resources for}
{drawing the close box, and two "PICT" resources for drawing the drag bar,}
{in order to demonstrate how you may add your own global variables in the}
{new record MyDataRecord. It uses the demo "OneEvents" instead of Skel,}
{in order to support the close box. The icons were taken from the WDEF demo}
{in the Mac Pascal programming book (available on the net).}
{This unit holds all custom code}
unit CustomStubs;
interface
uses
{$IFC UNDEFINED THINK_PASCAL}
Types, QuickDraw, ToolUtils, Windows, Events, OSUtils, Icons, Resources,
{$ENDC}
IngisWDEFUtils;
procedure GetGrowRgn (varCode: integer; macWindow: WindowPeek; var growRgn: RgnHandle);
procedure GetCloseBox (varCode: integer; dragBar: RgnHandle; var closeBox: Rect);
procedure GetZoomBox (varCode: integer; dragBar: RgnHandle; var zoomBox: Rect);
procedure DrawCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
procedure DrawZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
procedure DrawHitCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
procedure DrawHitZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
procedure DrawDragBar (varCode: integer; macWindow: WindowPeek; dragBar: RgnHandle; colorFlag: Boolean);
procedure BuildCustomRegions (varCode: integer; theRect: Rect; contRgn, dragRgn: RgnHandle);
procedure DrawScrollFrame (varCode: integer; macWindow: WindowPeek; theRect: Rect);
procedure DrawTheGrowIcon (varCode: integer; macWindow: WindowPeek; theRect: Rect; growRgn: RgnHandle; colorFlag: Boolean);
procedure InitMyWindow (varCode: integer; macWindow: WindowPeek);
procedure DisposeMyWindow (varCode: integer; macWindow: WindowPeek);
{** Constants **}
const
kFrameWidth = 1; { Thickness of frame around window. 1 is normal.}
kShadowLength = 1; { Size of drop shadow. 1 is normal.}
kMinDepthForColor = 4; { Smallest pixel size for color. 8 (256 colors) is normal. }
kMinWidth = 100; { Limits for the dragging rectangle? }
kMinHeight = 100;
type
MyDataRecord = record
theWindowState: WStateData;
{Insert any globals you need here!}
theCloseBoxCicn, theHitCloseBoxCicn: CIconHandle;
theDragPict, theInactiveDragPict: PicHandle;
end;
MyDataPtr = ^MyDataRecord;
MyDataHandle = ^MyDataPtr;
implementation
{*****************************************************************************}
{ GetGrowRgn}
{ Return the region with the grow icon, if any.}
{ *****************************************************************************}
procedure GetGrowRgn (varCode: integer; macWindow: WindowPeek; var growRgn: RgnHandle);
begin
{We don't support resizing}
end;
{*****************************************************************************}
{ GetCloseBox}
{ Pass back a rectangle which encloses the close box of the window}
{ *****************************************************************************}
procedure GetCloseBox (varCode: integer; dragBar: RgnHandle; var closeBox: Rect);
begin
with dragBar^^.rgnBBox do
SetRect(closeBox, left + 5, top + 3, left + 5 + (bottom - top - 4) - 2, bottom - 3);
end;
procedure GetZoomBox (varCode: integer; dragBar: RgnHandle; var zoomBox: Rect);
begin
{No zoom box}
end;
{*****************************************************************************}
{ Draw close box and zoom box, in normal and hit state }
{ Draw the close box in "hit" state. This can be as simple as an InvertRect. }
{ *****************************************************************************}
procedure DrawCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
begin
if colorFlag then
PlotCIcon(closeBox, MyDataHandle(macWindow^.dataHandle)^^.theCloseBoxCicn)
else
StdCloseBox(closeBox, colorFlag);
end; {}
procedure DrawZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
begin
{No zoom box}
end; {}
procedure DrawHitCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
begin
if colorFlag then
PlotCIcon(closeBox, MyDataHandle(macWindow^.dataHandle)^^.theHitCloseBoxCicn)
else
DrawStdCloseHit(closeBox);
end; {}
procedure DrawHitZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
begin
end; {}
{*****************************************************************************}
{ DrawDragBar, BW and Color version}
{ Draw the drag bar (not close box/zoom box)}
{ *****************************************************************************}
procedure DrawDragBar (varCode: integer; macWindow: WindowPeek; dragBar: RgnHandle; colorFlag: Boolean);
begin
if macWindow^.hilited then
DrawPicture(MyDataHandle(macWindow^.dataHandle)^^.theDragPict, dragBar^^.rgnBBox)
else
DrawPicture(MyDataHandle(macWindow^.dataHandle)^^.theInactiveDragPict, dragBar^^.rgnBBox);
end; {DrawDragBar}
{*****************************************************************************}
{ BuildCustomRegions}
{ Build the contents region and the drag bar region}
{ *****************************************************************************}
procedure BuildCustomRegions (varCode: integer; theRect: Rect; contRgn, dragRgn: RgnHandle);
var
tmpRect: Rect;
begin
OpenRgn;
FrameRoundRect(theRect, 10, 10);
CloseRgn(contRgn);
tmpRect := theRect;
InsetRect(tmpRect, 15, 0);
OffsetRect(tmpRect, 0, -18);
OpenRgn;
FrameRoundRect(tmpRect, 10, 10);
CloseRgn(dragRgn);
end; {BuildCustomRegions}
{*****************************************************************************}
{ DrawScrollFrame}
{ Draw the scroll frame, if any (used both when resizing and when drawing the grow icon) }
{ *****************************************************************************}
procedure DrawScrollFrame (varCode: integer; macWindow: WindowPeek; theRect: Rect);
begin
{No scroll frame - no resizing}
end; {DrawScrollFrame}
{*****************************************************************************}
{ DrawTheGrowIcon, BW and Color version}
{ Draw the grow icon, if any }
{ *****************************************************************************}
procedure DrawTheGrowIcon (varCode: integer; macWindow: WindowPeek; theRect: Rect; growRgn: RgnHandle; colorFlag: Boolean);
begin
{No grow}
end; {DrawTheGrowIcon}
{*****************************************************************************}
{ InitMyWindow and DisposeMyWindow }
{ Can often be empty. Set the spareFlag in InitMyWindow if the variant should have a zoom box. }
{ InitMyWindow may initialize any globals in MyDataHandle(macWindow^.dataHandle). }
{ DisposeMyWindow must restore/dispose fields in MyDataHandle(macWindow^.dataHandle) as needed. }
{ *****************************************************************************}
procedure InitMyWindow (varCode: integer; macWindow: WindowPeek);
begin
{No zoom}
if HasCQDraw then
begin
MyDataHandle(macWindow^.dataHandle)^^.theCloseBoxCicn := GetCIcon(128);
MyDataHandle(macWindow^.dataHandle)^^.theHitCloseBoxCicn := GetCIcon(129);
end;
MyDataHandle(macWindow^.dataHandle)^^.theDragPict := GetPicture(128);
MyDataHandle(macWindow^.dataHandle)^^.theInactiveDragPict := GetPicture(129);
end; {InitMyWindow}
procedure DisposeMyWindow (varCode: integer; macWindow: WindowPeek);
begin
if HasCQDraw then
begin
DisposeCIcon(MyDataHandle(macWindow^.dataHandle)^^.theCloseBoxCicn);
DisposeCIcon(MyDataHandle(macWindow^.dataHandle)^^.theHitCloseBoxCicn);
end;
ReleaseResource(Handle(MyDataHandle(macWindow^.dataHandle)^^.theDragPict));
ReleaseResource(Handle(MyDataHandle(macWindow^.dataHandle)^^.theInactiveDragPict));
end; {DisposeMyWindow}
end.